//
//  UnifiedNativeAdCustomView.m
//  SAMKit_Example
//
//  Created by 山刘 on 2020/4/23.
//  Copyright © 2020 samlau7245. All rights reserved.
//

#import "UnifiedNativeAdCustomView.h"

@implementation UnifiedNativeAdCustomView

- (instancetype)init {
    self = [super init];
    if (self) {
        [self seg_addSubView];
    }
    return self;
}
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self seg_addSubView];
    }
    return self;
}
- (void)seg_addSubView {
    [self addSubview:self.iconImageView];
    [self addSubview:self.imageView];
    [self addSubview:self.titleLabel];
    [self addSubview:self.descLabel];
    [self addSubview:self.clickButton];
}

/// refresh
- (void)setupWithUnifiedNativeAdObject:(GDTUnifiedNativeAdDataObject *)unifiedNativeDataObject {
    self.titleLabel.text = unifiedNativeDataObject.title;
    self.descLabel.text = unifiedNativeDataObject.desc;
    NSURL *iconURL = [NSURL URLWithString:unifiedNativeDataObject.iconUrl];
    NSURL *imageURL = [NSURL URLWithString:unifiedNativeDataObject.imageUrl];
    UIImage *normalIcon = [UIImage imageNamed:SEGPicName(@"pic_default_70_70")];
    if (self.iconPlaceholderImage) normalIcon = self.iconPlaceholderImage;
    [self.iconImageView setImageWithURL:iconURL placeholderImage:normalIcon];
    [self.imageView setImageWithURL:imageURL placeholderImage:[UIImage imageNamed:SEGPicName(@"pic_default_690_240")]];
}

#pragma mark - proerty getter
- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.accessibilityIdentifier = @"titleLabel_id";
    }
    return _titleLabel;
}
- (UILabel *)descLabel {
    if (!_descLabel) {
        _descLabel = [[UILabel alloc] init];
        _descLabel.accessibilityIdentifier = @"descLabel_id";
    }
    return _descLabel;
}
- (UIImageView *)iconImageView {
    if (!_iconImageView) {
        _iconImageView = [[UIImageView alloc] init];
        _iconImageView.accessibilityIdentifier = @"iconImageView_id";
        _iconImageView.contentMode = UIViewContentModeScaleAspectFill;
    }
    return _iconImageView;
}
- (UIImageView *)imageView {
    if (!_imageView) {
        _imageView = [[UIImageView alloc] init];
        _imageView.accessibilityIdentifier = @"imageView_id";
        _imageView.contentMode = UIViewContentModeScaleAspectFill;
    }
    return _imageView;
}
- (UIButton *)clickButton {
    if (!_clickButton) {
        _clickButton = [[UIButton alloc] init];
        _clickButton.accessibilityIdentifier = @"clickButton_id";
    }
    return _clickButton;
}

@end
